import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { makeStyles } from '@material-ui/core/styles';
import BottomNavigation from '@material-ui/core/BottomNavigation';
import BottomNavigationAction from '@material-ui/core/BottomNavigationAction';
import home1 from "@/assets/images/tabbar/home_1.png"
import home2 from "@/assets/images/tabbar/home_2.png"
import my1 from "@/assets/images/tabbar/my_1.png"
import my2 from "@/assets/images/tabbar/my_2.png"
import fast from "@/assets/images/tabbar/fast.png"
import "./Tabbar.less"
const useStyles = makeStyles({
    root: {
        width: 500,
    },
});

export default function SimpleBottomNavigation() {
    const classes = useStyles();
    const [value, setValue] = React.useState(0);
    const [isShow, setShow] = React.useState(true)
    let history = useHistory()

    useEffect(() => {
        // 判断当前页面要不要显示Tabbar底部栏
        // console.log(history.location.pathname);
        // if (["/home", "/fast", "/user"].includes((history.location.pathname))) {
        //     setShow(true)
        // } else {
        //     setShow(false)
        // }
        setShow(["/home", "/fast", "/user"].includes(history.location.pathname))
        setValue(["/home", "/fast", "/user"].indexOf(history.location.pathname))
    }, [history.location.pathname])

    return (
        <BottomNavigation
            style={{ display: isShow ? "flex" : "none" }}
            value={value}
            onChange={(event, newValue) => {
                // if (newValue === 0) {
                //     history.push("/home")
                // } else if (newValue === 1) {
                //     history.push("/fast")
                // } else if (newValue === 2) {
                //     history.push("/user")
                // }


                // switch (newValue) {
                //     case 0:
                //         history.push("/home");
                //         break;
                //     case 1:
                //         history.push("/fast");
                //         break;
                //     case 2:
                //         history.push("/user");
                //         break;
                //     default:
                //         break;
                // }

                let obj = {
                    "0": "/home",
                    "1": "/fast",
                    "2": "/user"
                }
                history.push(obj[newValue].toString());
                setValue(newValue);
            }}
            showLabels
            className={classes.root}
        >
            <BottomNavigationAction label="首页" icon={<img src={value === 0 ? home1 : home2} alt="" />} />
            <BottomNavigationAction label="快速刷题" icon={<img src={fast} alt="" />} />
            <BottomNavigationAction label="我的" icon={<img src={value === 2 ? my1 : my2} alt="" />} />
        </BottomNavigation>
    );
}